#include <bits/stdc++.h>
#define ll long long
#define ks ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

template<class T>inline void read(T &res) {
	char c;
	T flag = 1;
	while ((c = getchar()) < '0' || c > '9')
		if (c == '-')
			flag = -1;
	res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	res *= flag;
}

int getMinSwaps(vector<int> v) {
	vector<int> v1(v);
	sort(v1.begin(), v1.end());
	map<int, int> m;
	int len = v.size();
	for (int i = 0; i < len; i++) {
		m[v1[i]] = i;
	}
	int loops = 0;
	vector<bool> flag(len, false);

	for (int i = 0; i < len; i++) {
		if (!flag[i]) {
			int j = i;
			while (!flag[j]) {
				flag[j] = true;
				j = m[v[j]];
			}
			loops++;
		}
	}
	return len - loops;
}


int main() {
	int n, k;
	while (scanf("%d", &n) != EOF) {
		vector<int> v;
		while (n--) {

			scanf("%d", &k);
			v.push_back(k);

		}
		int num = getMinSwaps(v);
		printf("%d\n", num);
	}

}

